package poker.entities;

import poker.util.ConstantCardStrings;

public class Card {
	
	//card attributes
	private Force cardForce;
	private Symbol cardSymbol;
	
	//logical comparison attributes
	private int cardMatchingOccurrence;
	
	public Card(){
		cardForce = new Force();
		cardSymbol = new Symbol(null);
		cardMatchingOccurrence = 0;
	}
	public Card(Symbol symbol, Force force){
		if(!(symbol.toString().isEmpty() || symbol.toString() == null)){
			cardSymbol = symbol;
		}
		else{
			cardSymbol = null;
		}
		if(force.retrieve() > 0 && force.retrieve() <= ConstantCardStrings.ACE){
			cardForce = force;
		}
		else{
			cardForce = null;
		}
		cardMatchingOccurrence = 0;
	} 
	
	public String toString(){
		if(hasValidForce() && hasValidSymbol()){
			switch(cardForce.retrieve()){
				case ConstantCardStrings.JACK : return "["+cardSymbol.toString()+"][JACK]";
				case ConstantCardStrings.QUEEN: return "["+cardSymbol.toString()+"][QUEEN]";
				case ConstantCardStrings.KING: return "["+cardSymbol.toString()+"][KING]";
				case ConstantCardStrings.ACE: return "["+cardSymbol.toString()+"][ACE]";
				default:return "["+cardSymbol.toString()+"]["+cardForce.retrieve()+"]";
			}
		}
		else{
			return "[][]";
		}
	}
	
	/**
	 * 			isValid()
	 * @return true if both hasValidSymbol and hasValidForce return true
	 */
	public boolean isValid(){
		return hasValidSymbol() && hasValidForce()?true:false;
	}
	
	/**
	 * 		hasValidSymbol
	 * @return true if cardSymbol is not null and has a symbol name with the same string as the ones found in the ConstantCardStrings utility card.
	 */
	public boolean hasValidSymbol(){
		return cardSymbol!=null && (cardSymbol.toString().equals(ConstantCardStrings.CLUBS_SYMBOL)
		|| cardSymbol.toString().equals(ConstantCardStrings.DIAMONDS_SYMBOL)
		|| cardSymbol.toString().equals(ConstantCardStrings.HEARTS_SYMBOL)
		|| cardSymbol.toString().equals(ConstantCardStrings.SPADES_SYMBOL))?true:false;
	}
	
	/**
	 * 		hasValidForce
	 * @return true if cardForce is not null and is between 2 and 14 inclusive.
	 */
	public boolean hasValidForce(){
		return cardForce!=null && cardForce.retrieve() <= ConstantCardStrings.ACE && cardForce.retrieve() >= ConstantCardStrings.TWO?true:false; 
	}
	
	public Symbol getSymbol(){
		return cardSymbol;
	}
	
	public Force getForce(){
		return cardForce;
	}
	
	public boolean isGreater(Card card){
		if(cardForce.retrieve() > card.getForce().retrieve()){
			return true;
		}
		return false;
	}
	
	public boolean equals(Card card){
		return card.getForce().retrieve() == cardForce.retrieve()?true:false;
	}
	
	public boolean isExactSame(Card card){
		return card.getForce().retrieve() == cardForce.retrieve()
			&& card.getSymbol().toString().equals(cardSymbol.toString())?true:false;
	}
	
	public boolean isSameSymbol(Card card){
		return card.getSymbol().toString().equals(cardSymbol.toString())?true:false;
	}
	public int getCardMatchingOccurrence() {
		return cardMatchingOccurrence;
	}
	public void setCardMatchingOccurrence(int cardMatchingOccurrence) {
		this.cardMatchingOccurrence = cardMatchingOccurrence;
	}
	public void incrementOccurence(){
		cardMatchingOccurrence += 1;
	}
	public void resetOccurence(){
		cardMatchingOccurrence = 0;
	}

}
